/**
 * <p><b>Title:</b> PcProductPermissionController.java </p>
 *
 * @Package com.wondertek.poms.setting.controller
 */
package com.wondertek.poms.service.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wondertek.oes.sso.common.util.SecurityUtils;
import com.wondertek.poms.common.constant.Constants;
import com.wondertek.poms.common.controller.BaseController;
import com.wondertek.poms.common.log.MethodLog;
import com.wondertek.poms.common.utils.validate.ValidateFilter;
import com.wondertek.poms.common.vo.PageBean;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.feign.SSOFeignClient;
import com.wondertek.poms.core.service.IFirstProductInfoPackageService;
import com.wondertek.poms.core.service.IPcProductPermissionService;
import com.wondertek.poms.core.service.IPrdInfoService;
import com.wondertek.poms.core.service.IProductInfoPackageService;
import com.wondertek.poms.dao.po.FirstProductInfoPackage;
import com.wondertek.poms.dao.po.PcProductPermission;
import com.wondertek.poms.dao.po.PrdInfo;
import com.wondertek.poms.dao.po.ProductInfoPackage;
import com.wondertek.poms.dao.pojo.SsoGroupPojo;
import com.wondertek.poms.dao.vo.NodeVo;
import com.wondertek.poms.dao.vo.PcProductPermissionBackVo;
import com.wondertek.poms.dao.vo.PcProductPermissionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p><b>PcProductPermissionController Description:</b> 产品权限表Controller层实现</p>
 *
 * @author gaozhengxing
 * <p><b>DATE</b> 2019-08-12 12:45:35</p>
 */
@SuppressWarnings("JavaDoc")
@Api("产品权限")
@RestController
@Slf4j
@Scope("prototype")
@RequestMapping(value = "/pc-product-permission")
public class PcProductPermissionController extends BaseController {

    @Autowired
    private IPcProductPermissionService pcProductPermissionService;

    @Autowired
    private IFirstProductInfoPackageService firstProductInfoPackageService;
    @Autowired
    private IProductInfoPackageService productInfoPackageService;

    @Autowired
    private IPrdInfoService prdInfoService;

    @Autowired
    private SSOFeignClient ssoFeignClient;

    /**
     * 树形结构-选择类型 1:一级产品
     */
    public static final int TREE_SELECT_TYPE_1 = 1;
    /**
     * 树形结构-选择类型 2:二级产品
     */
    public static final int TREE_SELECT_TYPE_2 = 2;
    /**
     * 树形结构-选择类型 3:商品包
     */
    public static final int TREE_SELECT_TYPE_3 = 3;

    public static final String RESULT = "result";

    @ApiOperation("产品权限列表")
    @GetMapping("/list")
    @ResponseBody
    @MethodLog(module = "产品权限列表")
    public ResultBean list(HttpServletRequest request,
                           PcProductPermissionVo pcProductPermissionVo,
                           @RequestParam(defaultValue = "1") int page,
                           @RequestParam(defaultValue = "20") int rows,
                           @RequestParam(defaultValue = "updatedTime") String sidx,
                           @RequestParam(defaultValue = "desc") String sord) {

        PcProductPermission pcProductPermission = null;
        try {
            pcProductPermission = new PcProductPermission();
            BeanUtils.copyProperties(pcProductPermissionVo, pcProductPermission);
            Page<PcProductPermission> pages = pcProductPermissionService
                    .findAll(pcProductPermission, page, rows, sord, sidx);
            return PageBean.ok(pages.getTotalPages(), pages.getTotalElements(), pages.getContent());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @ApiOperation("产品权限新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fsPrdId", required = true),
            @ApiImplicitParam(name = "prdLevel", required = true),
            @ApiImplicitParam(name = "prdType", required = true),
            @ApiImplicitParam(name = "ugid", required = true),
            @ApiImplicitParam(name = "ugname", required = true),
            @ApiImplicitParam(name = "createdBy", required = true),
            @ApiImplicitParam(name = "createdTime", required = true),
            @ApiImplicitParam(name = "updatedBy", required = true),
            @ApiImplicitParam(name = "updatedTime", required = true),
            @ApiImplicitParam(name = "remakrs", required = true),
            @ApiImplicitParam(name = "deleted", required = true),
    })
    @PostMapping(value = "/add")
    @ResponseBody
    @MethodLog(module = "产品权限新增", insertDB = true)
    public ResultBean add(@RequestBody PcProductPermissionBackVo pcProductPermissionBackVo) {

        try {
            List<String> messageList = ValidateFilter.getFilterMessage(pcProductPermissionBackVo, Constants.VALIDATE_DEFAULT);
            if (!messageList.isEmpty()) {
                return ResultBean.error(messageList.toString());
            }
            //作编辑操作
            if (2 == pcProductPermissionBackVo.getType()) {
                //如果为编辑就先清空原来用户的的权限配置
                PcProductPermission pc = new PcProductPermission();
                pc.setUgid(pcProductPermissionBackVo.getUgid());
                //pc.setDeleted(Constants.DELETE_0);
                List<PcProductPermission> pcProductPermissions = pcProductPermissionService.findAll(Example.of(pc));
                for (PcProductPermission permission : pcProductPermissions) {
                    pcProductPermissionService.deleteById(permission.getId());
                }
            }
            //作新增操作
            if (1 == pcProductPermissionBackVo.getType()) {
                //
                PcProductPermission pc = new PcProductPermission();
                pc.setUgid(pcProductPermissionBackVo.getUgid());
                //pc.setDeleted(Constants.DELETE_0);
                List<PcProductPermission> pcProductPermissions = pcProductPermissionService.findAll(Example.of(pc));
                if (pcProductPermissions.size() > 0) {
                    return PageBean.error("该用户已经存在权限，请作编辑操作");

                }
            }
            List<NodeVo> nodeVos = pcProductPermissionBackVo.getNodeVos();
            if (!CollectionUtils.isEmpty(nodeVos)) {
                for (NodeVo nodeVo : nodeVos) {
                    Boolean twoFlag = false;  //在二级节点里面判断一级节点权限是否已经生成
                    Boolean thrFlag = false;  //在三级节点里面判断一级节点权限是否需要生成
                    if (1 == nodeVo.getIsShow()) {
                        //如果一级节点勾选,将一级节点节点及其子节点全部生成权限
                        generatePermission(pcProductPermissionBackVo, nodeVo);
                        generateNodeVo(pcProductPermissionBackVo, nodeVo);
                    } else {
                        //获取二级节点
                        List<NodeVo> secNodeVos = nodeVo.getChildren();
                        if (!CollectionUtils.isEmpty(secNodeVos)) {
                            //判断二级产品是否有勾选
                            if (checkNodeVos(secNodeVos)) {
                                //将一级节点生成权限
                                generatePermission(pcProductPermissionBackVo, nodeVo);
                                twoFlag = true;   //一级节点的权限已经生成
                            }
                            for (NodeVo secNode : secNodeVos) {
                                if (1 == secNode.getIsShow()) {
                                    //如果二级节点勾选，将二级节点及其子节点全部生成权限
                                    generatePermission(pcProductPermissionBackVo, secNode);
                                    //商品包权限
                                    List<NodeVo> thrNodeVos = secNode.getChildren();
                                    if (!CollectionUtils.isEmpty(thrNodeVos)) {
                                        for (NodeVo thrNodeVo : thrNodeVos) {
                                            if (1 == thrNodeVo.getIsShow()) {
                                                generatePermission(pcProductPermissionBackVo, thrNodeVo);
                                            }
                                        }
                                    }
                                } else {
                                    //获取三级节点
                                    List<NodeVo> thrNodeVos = secNode.getChildren();
                                    if (!CollectionUtils.isEmpty(thrNodeVos)) {
                                        //且存在三级节点勾选
                                        if (checkNodeVos(thrNodeVos)) {
                                            //将二级节点生成权限
                                            generatePermission(pcProductPermissionBackVo, secNode);
                                            if (!twoFlag) {
                                                thrFlag = true;
                                            }

                                        }
                                        for (NodeVo thrNodeVo : thrNodeVos) {
                                            if (1 == thrNodeVo.getIsShow()) {
                                                generatePermission(pcProductPermissionBackVo, thrNodeVo);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //如果在二级节点判断中没有生成一级节点权限，且在三级节点判断中需要生成一级节点权限
                        if (false == twoFlag && thrFlag) {
                            generatePermission(pcProductPermissionBackVo, nodeVo);
                        }
                    }

                }
            }

        } catch (Exception e) {
            log.info("添加用户权限所报的异常为", e);
        }
        return ResultBean.ok();
    }


    /**
     * 查看节点集合是否存在勾选的（若存在的话，则要将上一级的节点生成权限）
     *
     * @param nodeVos
     * @return
     */
    private Boolean checkNodeVos(List<NodeVo> nodeVos) {
        List<NodeVo> checkSecNodes = nodeVos.stream().filter(p -> p.getIsShow().equals(1)).collect(Collectors.toList());
        return !CollectionUtils.isEmpty(checkSecNodes);

    }


    /***
     * 将一级节点下面的权限全部生成
     * @param pcProductPermissionBackVo
     * @param nodeVo
     */

    private void generateNodeVo(PcProductPermissionBackVo pcProductPermissionBackVo, NodeVo nodeVo) {
        List<NodeVo> secNodeVos = nodeVo.getChildren();
        //二级产品权限
        if (!CollectionUtils.isEmpty(secNodeVos)) {
            for (NodeVo secNode : secNodeVos) {
                generatePermission(pcProductPermissionBackVo, secNode);
                //商品包权限
                List<NodeVo> thrNodeVos = secNode.getChildren();
                if (!CollectionUtils.isEmpty(thrNodeVos)) {
                    for (NodeVo thrNodeVo : thrNodeVos) {
                        generatePermission(pcProductPermissionBackVo, thrNodeVo);
                    }
                }
            }
        }
    }

    /**
     * 生成权限
     *
     * @param pcProductPermissionBackVo
     * @param nodeVo
     */
    private void generatePermission(PcProductPermissionBackVo pcProductPermissionBackVo, NodeVo nodeVo) {
        PcProductPermission pcProductPermission = new PcProductPermission();
        BeanUtils.copyProperties(pcProductPermissionBackVo, pcProductPermission, "id");
        pcProductPermission.setFsPrdId(Long.parseLong(nodeVo.getId().substring(4)));
        pcProductPermission.setPrdLevel(nodeVo.getType());
        pcProductPermission.setUpdatedTime(LocalDateTime.now());
        pcProductPermission.setIsShow(nodeVo.getIsShow());
        pcProductPermission.setUpdatedBy(SecurityUtils.getCurrentUserName());
        pcProductPermission.setDeleted(0);
        pcProductPermissionService.save(pcProductPermission);
    }

    @ApiOperation("产品权限详情")
    @ApiImplicitParam(name = "ugid", required = true, paramType = "query", dataType = "Long")
    @GetMapping(value = "/get")
    @ResponseBody
    @MethodLog(module = "产品权限详情")
    public ResultBean get(Long ugid) {
        if (null == ugid) {
            return ResultBean.error("ugid不能为空");
        }
        //获取全量产品树
        log.info("产品权限详情传的用户ID为======={}", ugid);
        List<NodeVo> nodeList = getFullNode();
        Map<String, NodeVo> nodes = new LinkedHashMap<>();
        for (NodeVo node : nodeList) {
            nodes.put(node.getId(), node);
        }
        //获取当前编辑的产品权限
        PcProductPermissionBackVo pcProductPermissionBackVo = new PcProductPermissionBackVo();
        //复制从前端返回的用户信息

        PcProductPermission pc = new PcProductPermission();
        pc.setUgid(ugid);
        pc.setDeleted(Constants.DELETE_0);
        //查询当前用户下的所有权限配置
        //已经勾选的所有节点
        List<NodeVo> selectNodeVo = new ArrayList<>();
        List<PcProductPermission> pcProductPermissions = pcProductPermissionService.findAll(Example.of(pc));
        if (!pcProductPermissions.isEmpty()) {
            BeanUtils.copyProperties(pcProductPermissions.get(0), pcProductPermissionBackVo);
        }
        if (!pcProductPermissions.isEmpty()) {
            for (PcProductPermission permission : pcProductPermissions) {
                //保存一级产品节点
                if (1 == permission.getPrdLevel()) {
                    //获取一级节点
                    NodeVo firNodeVo = nodes.get("fir-" + permission.getFsPrdId());
                    //添加一级节点
                    if (1 == permission.getIsShow()) {
                        log.info("firNodeVo======{}", firNodeVo);
                        selectNodeVo.add(firNodeVo);
                    }
                }
                //保存二级节点
                if (2 == permission.getPrdLevel()) {
                    //获取当前二级节点
                    NodeVo secNodeVo = nodes.get("two-" + permission.getFsPrdId());
                    //添加二级结点
                    if (1 == permission.getIsShow()) {
                        log.info("secNodeVo====={}", secNodeVo);
                        selectNodeVo.add(secNodeVo);
                    }
                }
                if (3 == permission.getPrdLevel()) {
                    //添加三级节点
                    NodeVo thrNodeNo = nodes.get("thr-" + permission.getFsPrdId());
                    if (1 == permission.getIsShow()) {
                        log.info("thrNodeNo===={}", thrNodeNo);
                        selectNodeVo.add(thrNodeNo);
                    }
                }

            }
        }
        log.info("已经勾选的节点为=={}" + selectNodeVo);
        if (null != selectNodeVo && selectNodeVo.size() > 0) {
            selectNodeVo.forEach(node -> {
                node.setIsShow(1);  //将节设置为勾选
                nodes.put(node.getId(), node);
            });
        }
        pcProductPermissionBackVo.setNodeVos(getNodeVoJson("0", nodes));

        return ResultBean.ok(pcProductPermissionBackVo);
    }

    /**
     * 获取全量树
     *
     * @return
     */
    public List<NodeVo> getFullNode() {
        // 一级产品列表
        List<FirstProductInfoPackage> pfs = firstProductInfoPackageService.findAll();
        // 二级产品列表
        ProductInfoPackage selctPc = new ProductInfoPackage();
        //过滤出批价的二级产品包
        selctPc.setSystemFlag(ProductInfoPackage.systemFlag_1);
        List<ProductInfoPackage> pss = productInfoPackageService.findAll(Example.of(selctPc));

        //保存所有节点
        List<NodeVo> nodeVoList = new ArrayList<>();
        pfs.forEach(pf -> {
            String path = pf.getFirstProductName();
            NodeVo first = NodeVo.builder()
                    .id("fir-" + pf.getFirstProductId())
                    .type(TREE_SELECT_TYPE_1)
                    .name(pf.getFirstProductName())
                    .parentId("0")
                    .isShow(0)
                    .path(path)
                    .build();

            //筛选二级产品
            getSecondInProductFirst(pss, pf.getFirstProductId(), nodeVoList, path);

            //first.setChildren(childSecond);
            nodeVoList.add(first);
        });
        return nodeVoList;
    }

    /**
     * 把符合一级产品的二级产品过滤出来
     *
     * @param pss         二级产品列表
     * @param id          一级产品ID
     * @param nodeVoList  一级产品列表
     * @param path_parent 父节点路径（对应一级节点路径）
     */

    private void getSecondInProductFirst(List<ProductInfoPackage> pss, Long id, List<NodeVo> nodeVoList, String path_parent) {
        pss.forEach(ps -> {
            String path = path_parent + "/" + ps.getProductInfoPackageName();
            if (ps.getFirstProductInfoPackageId().equals(id)) {
                NodeVo second = NodeVo.builder()
                        .id("two-" + ps.getProductInfoPackageId())
                        .type(TREE_SELECT_TYPE_2)
                        .name(ps.getProductInfoPackageName())
                        .parentId("fir-" + id)
                        .isShow(0)
                        .path(path)
                        .build();

                nodeVoList.add(second);
                getPrdInfoInProductSecond(ps, nodeVoList, path);


            }

        });
    }


    /**
     * 查询在二级产品下存在的商品包
     *
     * @param ps          二级产品包
     * @param nodeVoList  保存的节点
     * @param path_parent 对应的二级节点路径
     */
    private void getPrdInfoInProductSecond(ProductInfoPackage ps, List<NodeVo> nodeVoList, String path_parent) {
        PrdInfo ppi = new PrdInfo();
        //ppi.setIsPublish(2);
        ppi.setProductInfoPackageId(ps.getProductInfoPackageId());
        ppi.setSystemFlag(PrdInfo.prdInfoSystemFlag_1);
        List<PrdInfo> pis = prdInfoService.findAll(Example.of(ppi));
        pis.forEach(pi -> {
            String path = path_parent + "/" + pi.getName();
            NodeVo third = NodeVo.builder()
                    .id("thr-" + pi.getPrdInfoId())
                    .type(TREE_SELECT_TYPE_3)
                    .name(pi.getName())
                    .parentId("two-" + ps.getProductInfoPackageId())
                    .isShow(0)
                    .path(path)
                    .build();
            nodeVoList.add(third);


        });
    }


    /**
     * 递归处理   数据库树结构数据->树形json
     *
     * @param nodeId
     * @param nodes
     * @return
     */
    public List<NodeVo> getNodeVoJson(String nodeId, Map<String, NodeVo> nodes) {
        //当前层级当前node对象
//        NodeVo cur = nodes.get(nodeId);
        //当前层级当前点下的所有子节点
        List<NodeVo> childList = getChildNodeVos(nodeId, nodes);
        List<NodeVo> nodeVos = new ArrayList<>();
        for (NodeVo node : childList) {
            NodeVo o = NodeVo.builder().id(node.getId())
                    .isShow(node.getIsShow())
                    .parentId(node.getParentId())
                    .type(node.getType())
                    .path(node.getPath())
                    .name(node.getName()).build();
            List<NodeVo> childs = getNodeVoJson(node.getId(), nodes);  //递归调用该方法
            if (!childs.isEmpty()) {
                o.setChildren(childs);
            }
            nodeVos.add(o);
        }
        return nodeVos;
    }

    /**
     * 获取当前节点的所有子节点
     *
     * @param nodeId
     * @param nodes
     * @return
     */
    public List<NodeVo> getChildNodeVos(String nodeId, Map<String, NodeVo> nodes) {
        List<NodeVo> list = new ArrayList<>();
//		for (String key : nodes.keySet() ) {
//			if(nodes.get(key).getParentId().equals(nodeId)){
//				list.add(nodes.get(key));
//			}
//		}

        for (NodeVo value : nodes.values()) {
            if (value.getParentId().equals(nodeId)) {
                list.add(value);
            }
        }


        return list;
    }


    @ApiOperation("产品权限删除")
    @ApiImplicitParam(name = "ugid", required = true, paramType = "query", dataType = "Long")
    @DeleteMapping(value = "/del")
    @ResponseBody
    @MethodLog(module = "产品权限删除", insertDB = true, opterate = 3)
    public ResultBean delete(Long ugid) {
        if (null == ugid) {
            return ResultBean.error("ugid不能为空");
        }
        PcProductPermission pc = new PcProductPermission();
        pc.setUgid(ugid);
        pc.setDeleted(Constants.DELETE_0);
        //查询当前用户下的所有权限配置
        List<PcProductPermission> pcProductPermissions = pcProductPermissionService.findAll(Example.of(pc));
        for (PcProductPermission pcProductPermission : pcProductPermissions) {
            pcProductPermissionService.deleteLogic(pcProductPermission.getId());
        }
        return ResultBean.ok();

    }

    /**
     * 产品树型结构
     *
     * @return
     */
    @GetMapping("/tree")
    @ResponseBody
    @MethodLog(module = "产品树型结构")
    public ResultBean getNodeTree() {
        //获取全量产品树
        List<NodeVo> nodeList = getFullNode();
        Map<String, NodeVo> nodes = new LinkedHashMap<>();
        for (NodeVo node : nodeList) {
            nodes.put(node.getId(), node);
        }
        return PageBean.ok(getNodeVoJson("0", nodes));
    }


    /**
     * 只过滤出该用户的全量权限树
     *
     * @param
     * @return
     */
    @SuppressWarnings("DanglingJavadoc")
    @GetMapping(value = "/get-user-full-tree")
    public ResultBean getUserFullTree(HttpServletRequest request) throws IOException {

        /******************************************************************************************************************
         *
         * 用户权限
         *
         ******************************************************************************************************************/
        String currentUserId = SecurityUtils.getCurrentUser().getUserId().toString();
        String currentUserName = SecurityUtils.getCurrentUserName();
        log.info("getUserFullTree=========当前登录的用户ID和当前登录用户名称为======currentUserId={},currentUserName={}", currentUserId, currentUserName);
        PcProductPermission pc = new PcProductPermission();
        pc.setUgid(Long.parseLong(currentUserId));
        pc.setDeleted(Constants.DELETE_0);
        pc.setUserType(1);
        List<PcProductPermission> pcProductPermissions = pcProductPermissionService.findAll(Example.of(pc));//根据用户获取的权限


        /******************************************************************************************************************
         *
         * 组权限
         *
         ******************************************************************************************************************/
        Cookie[] cookies = request.getCookies();
        String value = null;
        for (Cookie element : cookies) {
            String name = element.getName();
            if (StringUtils.equals(name, "accessToken")) {
                value = element.getValue();
                break;
            }
        }
        if (StringUtils.isBlank(value)) {
            ResultBean.error("根据用户组id查询用户id列表失败");
        }
        String userIdByGroupId = ssoFeignClient.getGroupInfoByUser(value);
        JSONObject jsonObject = JSON.parseObject(userIdByGroupId);
        if (!"90000".equals(jsonObject.getString("code"))) {
            return PageBean.error(jsonObject.getString("message"));
        }
        String result = jsonObject.getString(RESULT);
        ObjectMapper mapper = new ObjectMapper();
        List<SsoGroupPojo> groupList = mapper.readValue(result, new TypeReference<List<SsoGroupPojo>>() {
        });
        log.info("当前用户的群组列表|{}", groupList);

        if (CollectionUtil.isNotEmpty(groupList)) {
            for (SsoGroupPojo group : groupList) {
                Long groupId = group.getGroupId();
                //去权限表查组的权限
                PcProductPermission pcParam = new PcProductPermission();
                pcParam.setUgid(groupId);
                pcParam.setDeleted(Constants.DELETE_0);
                pcParam.setUserType(2);
                List<PcProductPermission> pcProductPermissionGroups = pcProductPermissionService.findAll(Example.of(pcParam));//根据用户组获取的权限
                pcProductPermissions.addAll(pcProductPermissionGroups);
            }
        }


        //获取全量产品树
        List<NodeVo> nodeList = getFullNode();
        Map<String, NodeVo> nodes = new LinkedHashMap<>();
        for (NodeVo node : nodeList) {
            nodes.put(node.getId(), node);
        }
        if (!"administrator".equals(currentUserName)) {
            //过滤出该用户的全量权限树
            List<NodeVo> UserNodeVoList = new ArrayList<>();
            Map<String, NodeVo> treeNodeVos = new LinkedHashMap<>();
            for (PcProductPermission permission : pcProductPermissions) {
                //保存一级产品节点
                if (1 == permission.getPrdLevel()) {
                    //获取一级节点
                    NodeVo firNodeVo = nodes.get("fir-" + permission.getFsPrdId());
                    log.info("firNodeVo====:{}", firNodeVo);
                    UserNodeVoList.add(firNodeVo);
                }
                //保存二级节点
                if (2 == permission.getPrdLevel()) {
                    //获取当前二级节点
                    NodeVo secNodeVo = nodes.get("two-" + permission.getFsPrdId());
                    log.info("secNodeVo====={}", secNodeVo);
                    UserNodeVoList.add(secNodeVo);

                }
                if (3 == permission.getPrdLevel()) {
                    //添加三级节点
                    NodeVo thrNodeNo = nodes.get("thr-" + permission.getFsPrdId());
                    log.info("thrNodeNo===={}", thrNodeNo);
                    UserNodeVoList.add(thrNodeNo);

                }
            }
            log.info("getUserFullTree =======UserNodeVoList=={}", UserNodeVoList.toString());
            if (!UserNodeVoList.isEmpty()) {
                for (NodeVo node : UserNodeVoList) {
                    treeNodeVos.put(node.getId(), node);
                }
            } else {
                return ResultBean.error("该用户没有配置产品展现的菜单权限，请联系管理员配置产品展现的菜单权限");
            }
            log.info("getUserFullTree =======treeNodeVos==={}", treeNodeVos.toString());
            if (!treeNodeVos.isEmpty()) {
                return ResultBean.ok(getNodeVoJson("0", treeNodeVos));
            }
        }
        log.info("nodes====={}", toString());
        return ResultBean.ok(getNodeVoJson("0", nodes));
    }


}
